/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Ex6_ex3;

/**
 *
 * @author Root
 */
public class CheckingAccount extends Account {

    private double overdrafProtecttion=0;

    public CheckingAccount(double balance) {
        super(balance);
    }

    public double getOverdrafProtecttion() {
        return overdrafProtecttion;
    }


    public CheckingAccount(double balance, double protect) {
        super(balance);
        this.overdrafProtecttion = protect;
//        System.out.println("creating checking account with a " + balance + " balance and " + protect + " in overdraft protection");
    }

    @Override
    public String toString() {
        if(this.getOverdrafProtecttion()>0)
        return "CheckingAccount with a " +getBalance()+ " balance and "+overdrafProtecttion+" overdraf Protecttion"  ;
        else
        return "CheckingAccount with a " +getBalance()+" balance and no overdraf Protecttion"  ;

    }


    @Override
    public boolean withdraw(double amt) {
//        return super.withdraw(amt);
        if (amt <= balance) {
            balance -= amt;
            return true;
        } else if (amt > balance) {
            if (amt < (balance + overdrafProtecttion)) {
                
                overdrafProtecttion -= (amt - balance);
                balance = 0;
                return true;
            } else {
                return false;
            }

        }
        return false;
    }

    String toString2() {
       return "has a balance of "+balance;
    }
}
